package com.baomibing.flow.service.impl;

import com.baomibing.core.common.SearchResult;
import com.baomibing.flow.dto.SysFlowHistoryTaskDto;
import com.baomibing.flow.entity.SysFlowHistoryTask;
import com.baomibing.flow.mapper.SysFlowHistoryTaskMapper;
import com.baomibing.flow.service.SysFlowHistoryTaskService;
import com.baomibing.orm.base.MBaseServiceImpl;
import com.baomibing.tool.util.Checker;
import com.baomibing.tool.util.ObjectUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SysFlowHistoryTaskServiceImpl
 *
 * @author frog 2023/10/16 10:27
 * @version 1.0.0
 **/
@Service
public class SysFlowHistoryTaskServiceImpl extends MBaseServiceImpl<SysFlowHistoryTaskMapper, SysFlowHistoryTask, SysFlowHistoryTaskDto> implements SysFlowHistoryTaskService {

    @Override
    public void saveHistoryTask(SysFlowHistoryTaskDto task) {
        saveIt(task);
    }

    @Override
    public void saveHistoryTasks(List<SysFlowHistoryTaskDto> tasks) {
        saveItBatch(tasks);
    }

    @Override
    public void updateHistoryTask(SysFlowHistoryTaskDto task) {
        updateIt(task);
    }

    @Override
    public SearchResult<SysFlowHistoryTaskDto> listUserHistoryTaskByInstance(String userNo, int pageNo, int pageSize) {
        if (Checker.beEmpty(userNo)) {
            return new SearchResult<>();
        }
        return search(lambdaQuery().eq(SysFlowHistoryTask::getActor, userNo), pageNo, pageSize);
    }

    @Override
    public List<SysFlowHistoryTaskDto> listLatestHistoryTaskByInstance(String instanceId) {
        return null;
    }

    @Override
    public Integer maxStepByInstance(String instanceId) {
        if (Checker.beEmpty(instanceId)) {
            return 0;
        }
        Integer it = baseMapper.maxStepByInstance(instanceId);
        return ObjectUtil.defaultIfNull(it, 0);
    }
}
